<?php
	include("includes/secure.php");
	include("includes/config.php");
	include("includes/class/contract_company.class.php");
	
	$contract_company = new Contract_company();
	$eps = $contract_company->epsList();
	$arp = $contract_company->arpList();
	$afp = $contract_company->afpList(); 
	$coco_code	= $_GET['coco_code'];
	
	$msg_info = $msg_alert = $msg_error = false;
	$_SESSION['msg_cool'] = '';
	$show_msg = 0;
	
	$data = $contract_company->getContractCompanyData($coco_code);
	
	$company = $contract_company->companyList();

	
	if(isset($_POST['edit']) && $_POST['edit'] == 1){
		$new_data->coco_code			= $_POST['coco_code'];
		$new_data->hdvc_code 		= trim(mysql_real_escape_string($_POST['hdvc_code']));
		$new_data->coco_type 		= trim(mysql_real_escape_string($_POST['coco_type']));
		$new_data->coco_value 	= trim(mysql_real_escape_string($_POST['coco_value']));
		$new_data->coco_pay 		= trim(mysql_real_escape_string($_POST['coco_pay']));
		$new_data->coco_pay_value   	= trim(mysql_real_escape_string($_POST['coco_pay_value']));
		$new_data->coco_date_in 	=  cambiarFormatoFecha($_POST['coco_date_in'],2);
		$new_data->coco_date_out 	=  cambiarFormatoFecha($_POST['coco_date_out'],2);
		if (($_POST['coco_admin']) == ''){
		$new_data->coco_admin = 0;
		}
		else {
		$new_data->coco_admin = trim(mysql_real_escape_string($_POST['coco_admin']));
		}
		if (($_POST['coco_aporte_mutual']) == ''){
		$new_data->coco_aporte_mutual = 0;
		}
		else {
		$new_data->coco_aporte_mutual = trim(mysql_real_escape_string($_POST['coco_aporte_mutual']));
		}
		$new_data->eps_code 		= trim(mysql_real_escape_string($_POST['eps_code']));
		$new_data->arp_code 		= trim(mysql_real_escape_string($_POST['arp_code']));
		$new_data->afp_code 		= trim(mysql_real_escape_string($_POST['afp_code']));
		
		$new_data->coco_rep 		= trim(mysql_real_escape_string($_POST['coco_rep']));
		$new_data->coco_rep_ced 		= trim(mysql_real_escape_string($_POST['coco_rep_ced']));
		$new_data->coco_rep_tel1 		= trim(mysql_real_escape_string($_POST['coco_rep_tel1']));
		$new_data->coco_rep_tel2 		= trim(mysql_real_escape_string($_POST['coco_rep_tel2']));
		
		$new_data->coco_description = trim(mysql_real_escape_string($_POST['coco_description']));
		
		if ( $contract_company->updateContractCompany($new_data) ){
			$_SESSION["msg_cool"] .= 'El contrato fue actualizado..<br />';
			echo "<script> window.location.href='listContractCompany.php?show_msg=3'</script>";
			
		}
		else{
			$msg_error = true;
			$_SESSION["msg_cool"] .= 'No se pudo actualizar el contrato...<br />';
			echo "<script> window.location.href='listContractCompany.php?show_msg=1'</script>";	
		}		
	}
	
	if ( $msg_error )
		$show_msg = 1;
	elseif ( $msg_alert )
		$show_msg = 2;
	elseif ( $msg_info )
		$show_msg = 3;
?>